package generic;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA
 * Description:泛型的继承和通配符学习
 * User:22954
 * Date:2024-02-28
 * Time:20:22
 */
@SuppressWarnings("all")
public class ExtendGeneric {
    /*
    1.泛型不具备继承性
    2.通配符: <?> / <? extends E> / <? super E>
     */
    public static void main(String[] args) {
        ArrayList<Object> objects = new ArrayList<>();
        ArrayList<String> strings = new ArrayList<>();
        ArrayList<AAA> aaas = new ArrayList<>();
        ArrayList<BBB> bbbs = new ArrayList<>();
        ArrayList<CCC> cccs = new ArrayList<>();

        print1(objects);
        print1(strings);
        print1(aaas);
        print1(bbbs);
        print1(cccs);
        System.out.println("================");
//        print2(objects);//×
//        print2(strings);//×
//        print2(aaas);//×
        print2(bbbs);
        print2(cccs);
        System.out.println("==================");
        print3(objects);
//        print3(strings);//×
        print3(aaas);
        print3(bbbs);
//        print3(cccs);//×
    }
    /*
    <?>支持传入任意泛型类型
     */
    public static void print1(ArrayList<?> list) {
        System.out.println("<?>");
    }
    /*
    <? extends BBB>支持传入BBB类和BBB的子类,规定了传入泛型的上限
     */
    public static void print2(ArrayList<? extends BBB> list) {
        System.out.println("<? extends AAA>");
    }
    /*
    <? extends BBB>支持传入BBB类和BBB类的父类(包括直接父类),规定了传入泛型的下限
     */
    public static void print3(ArrayList<? super BBB> list){
        System.out.println("<? extends BBB>");
    }
}

@SuppressWarnings("all")
class AAA {
}

@SuppressWarnings("all")
class BBB extends AAA {
}

@SuppressWarnings("all")
class CCC extends BBB {
}
